#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>


#include <conio.h>
#include <unistd.h>
#include <windows.h>


#define INIT_PADLEN 4
#define WIDTH 31
#define HEIGHT 20


#define X_POS 0
#define Y_POS 1
#define BALL_SPEED 0.3
#define PROP_SPEED_P1 0.2
#define PROP_SPEED_P2 0.23    //左边发球，公平起见，右边的道具更快

#define FPS 60

#define LEFTWIN 0
#define RIGHTWIN 1

#define MAX_NAME_LEN 31
#define FILENAME "history.txt"

#define PASSWORD 123456


struct info {
    char name[MAX_NAME_LEN];
    int total;
    int win;
    float ratio;
};

typedef struct node
{
    struct info * info;
    struct node* next;
} Node;

//ball
struct ball
{
    float pos[2];
    float dirc[2];
    float speed;
};


void gotoxy(int m, int n); //光标移动

void init_map(char[][WIDTH]);

void printout(char[][WIDTH]);

void board(char[][WIDTH], int[], int[]);

bool board_start(char map[][WIDTH], int pos1[], int pos2[]);

bool ball_upd(char[][WIDTH], const int, const int, struct ball *);

void ball_board_check(int, int, struct ball *);

void upd_screen(char map[][WIDTH], char pre_map[][WIDTH]);

void printout(char map[][WIDTH]);

void delay(int);

void animation();

bool win_ani(bool,char map[][WIDTH],int board_pos1[],int board_pos2[],struct ball*,struct ball*,struct ball*);

int delay_ani(int milisec , int ctrl);

void summarize(Node *list, int score[]); 

void score_st(int score[]); 

void print_d_num(int score[]);

void print_num (int x, int y, int n);

void ball_pop_1(char map[][WIDTH], const int B1,const int B2,struct ball *b);

void ball_pop_2(char map[][WIDTH], const int B1,const int B2,struct ball *b);

void prop_upd_1(char map[][WIDTH],const int B1,const int B2,struct ball *b);

void prop_upd_2(char map[][WIDTH],const int B1,const int B2,struct ball *b);
